package com.epam.tcs.dao.hibernate.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import java.util.List;

@Entity
@Table(name = "tcs_student")
public class Student  implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4818708915619528786L;
	private Long student_id;
	private String firstName;
	private String middleName;
	private String lastName;
	private Date birthday;
	private String phone;
	private String email;
	private String description;
	private Group group;
	private Date dateAdded;
	private Date dateModified;
	private Date dateClosed;

	private List<JournalLectureStatus> journalLectureStatuses;
	private List<JournalPracticeStatus> journalPracticeStatuses;

	public Student(){}
	
	public Student(String firstName, String middleName, String lastName,
			Date birthday, String phone, String email, String description,
			Group group, Date dateAdded, Date dateModified, Date dateClosed) {
		this.firstName = firstName;
		this.middleName = middleName;
		this.lastName = lastName;
		this.birthday = birthday;
		this.phone = phone;
		this.email = email;
		this.description = description;
		this.group = group;
		this.dateAdded = dateAdded;
		this.dateModified  = dateModified;
		this.dateClosed = dateClosed;
	}

	@Id
	@Column(name = "student_id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getStudent_id() {
		return student_id;
	}

	public void setStudent_id(Long student_id) {
		this.student_id = student_id;
	}
	
	@Column(name = "first_name", length = 40)
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "middle_name", length = 40)
	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	@Column(name = "last_name", length = 40)
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "birthday")
	@Temporal(value = TemporalType.DATE)
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "phone", length = 12)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "email", length = 40)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

//	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
	@JoinColumn(name = "group_id", nullable = false)
	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	@Column(name = "date_added")
	@Temporal(value = TemporalType.TIMESTAMP)
	public Date getDateAdded() {
		return dateAdded;
	}

	public void setDateAdded(Date dateAdded) {
		this.dateAdded = dateAdded;
	}

	@Column(name = "date_modified")
	@Temporal(value = TemporalType.TIMESTAMP)
	public Date getDateModified() {
		return dateModified;
	}

	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}

	@Column(name = "date_closed")
	@Temporal(value = TemporalType.TIMESTAMP)
	public Date getDateClosed() {
		return dateClosed;
	}

	public void setDateClosed(Date dateClosed) {
		this.dateClosed = dateClosed;
	}
	
//	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "student")
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "student")
	public List<JournalLectureStatus> getJournalLectureStatuses() {
		return journalLectureStatuses;
	}

	public void setJournalLectureStatuses(
			List<JournalLectureStatus> journalLectureStatuses) {
		this.journalLectureStatuses = journalLectureStatuses;
	}

//	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "student")
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "student")
	public List<JournalPracticeStatus> getJournalPracticeStatuses() {
		return journalPracticeStatuses;
	}

	public void setJournalPracticeStatuses(
			List<JournalPracticeStatus> journalPracticeStatuses) {
		this.journalPracticeStatuses = journalPracticeStatuses;
	}

}
